package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.StoCarrierVO;
import com.yunxi.sto.service.StoCarrierDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 承运商信息 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-05-14
 */
@RestController
@RequestMapping("/admin/stoCarrier")
@Api(tags = "sto:carrier", description = "承运商信息接口")
public class StoCarrierController {
 private static final Logger logger = LoggerFactory.getLogger(StoCarrierController.class);

 /*@Reference(version = "${demo.service.version}",
           application = "${dubbo.application.id}",
           url = "${dubbo.application.url}",
           check = false,
           timeout = 10000)*/
 @Autowired
 StoCarrierDubboService stoCarrierDubboService;

 @GetMapping("/page")
 @ApiOperation(value = "查询分页")
 public ApiResult page(StoCarrierVO stoCarrierVO, @RequestParam(required = true)Integer pageNum, @RequestParam(required = true)Integer pageSize) throws Exception {
  return ResponseUtil.ok(stoCarrierDubboService.findPageByVO(stoCarrierVO,pageNum,pageSize));
 }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 @ApiImplicitParam(paramType="query", name = "carrierId", value = "主键id", required = true, dataType = "String")
 public ApiResult load(String carrierId, @CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(stoCarrierDubboService.getById(carrierId));
 }

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody StoCarrierVO stoCarrierVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoCarrierVO.setCreateBy(loginInfo.getUserCode());
  stoCarrierVO.setUpdateBy(loginInfo.getUserCode());
  stoCarrierDubboService.saveOrUpdate(stoCarrierVO);
  return ResponseUtil.ok("success");
 }

 @PostMapping("/del")
 @ApiOperation(value = "作废")
 public ApiResult del(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
//    stoCarrierDubboService.removeById(stoCarrierVO.getCarrierId());
  stoCarrierDubboService.del(list,1,loginInfo.getUserCode());
 return ResponseUtil.ok("success");
 }

 @PostMapping("/reset")
 @ApiOperation(value = "恢复")
 public ApiResult reset(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoCarrierDubboService.reset(list,0,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/frozen")
 @ApiOperation(value = "冻结")
 public ApiResult frozen(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoCarrierDubboService.frozen(list,1,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/frozenReset")
 @ApiOperation(value = "解冻")
 public ApiResult frozenReset(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoCarrierDubboService.frozenReset(list,0,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

}
